<template>
  <div class="my_div">
    <img src="../image/g1.jpg" alt="" />
    <h4 :style="{ backgroundColor: colorstr }" @click="btn">
      这是一个孤独可怜的狗子
    </h4>
  </div>
</template>

<script>
export default {
    data () {
        return {
            colorstr:''
        }
    },
    methods: {
        btn(){
            this.colorstr=`rgb(${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)})`

        }
    }
};
</script>

<style>
.my_div {
  width: 200px;
  border: 1px solid #000;
  text-align: center;
  float: left;
}
img {
  width: 100%;
}
</style>